home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvinput.cpp < prev    next >
Text File  |  1998-01-05  |  20KB  |  887 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVINPUT.CPP                          |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Input box implementation             |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #define uses_stdio
  16. #define uses_math
  17. #define uses_string
  18. #define uses_basics
  19. #define uses_dc
  20. #define uses_dialog
  21. #define uses_hist
  22. #define uses_icons
  23. #define uses_input
  24. #define uses_lines
  25. #define uses_stddlg
  26. #define uses_system
  27.  
  28. #include "PVuses.h"
  29.  
  30.  
  31. //Tinput_editor publics:
  32.  
  33. Tinput_editor::Tinput_editor(  char *_line, int _max_len, int _xl ):
  34.   Tmemo( _line, _max_len+1, _xl, 1 )
  35. {
  36.   ~text_editor->valid_chars;
  37.   for( int i = 32; i < 256; i++ )
  38.     text_editor->valid_chars << i;
  39.   left_icon = NEW( Ticon( "|i", cmLEFT_ARROW, 0 ) );
  40.     left_icon->set_flags( bfREPEAT, 1 );
  41.     left_icon-> set_state( isHIDDEN, 1 );
  42.     put_in( left_icon, -1, 0 );
  43.   right_icon = NEW( Ticon( "|i", cmRIGHT_ARROW, 0 ) );
  44.     right_icon->set_flags( bfREPEAT, 1 );
  45.     put_in( right_icon, xl, 0 );
  46.     right_icon->set_state( isHIDDEN, 1 );
  47. }
  48.  
  49. void Tinput_editor::scroll_to( int _x, int _y )
  50. {
  51.   int l;
  52.  
  53.   l = text_editor->buf_len - _x;
  54.   if( l < xl - 1 )
  55.   {
  56.     _x += l - xl + 1;
  57.     if( _x < 0 ) _x = 0;
  58.   }
  59.   Teditor::scroll_to( _x, _y );
  60. }
  61.  
  62. //Tinput_editor protected:
  63.  
  64. void Tinput_editor::get_focused( void )
  65. {
  66.   text_editor->set_select( 0, text_editor->buf_len, 1 );
  67. }
  68.  
  69. #ifndef HGR
  70. void Tinput_editor::set_palette( void )
  71. {
  72.   Teditor::set_palette();
  73.   if( !graph_flag )
  74.   {
  75.     text_attr = rolb( text_attr, 4 );
  76.     bold_attr &= 0x0F;
  77.     bold_attr |= (char) ( text_attr & 0xF0 );
  78.   }
  79. }
  80. #endif
  81.  
  82. void Tinput_editor::event_handler( Tevent &ev )
  83. {
  84.   Teditor::event_handler( ev );
  85.   if( state( isFOCUSED ) && ( ev.code == evCOMMAND ) )
  86.   {
  87.     switch( ev.CMD_CODE )
  88.     {
  89.       case cmLEFT_ARROW:
  90.         scroll_to( delta_x - 1, 1 ); break;
  91.       case cmRIGHT_ARROW:
  92.         scroll_to( delta_x + 1, 1 ); break;
  93.       default:
  94.         goto hot;
  95.     }
  96.     redraw();
  97.     handled( ev );
  98.   }
  99. hot:
  100.   left_icon->set_state( isHIDDEN, !delta_x );
  101.   right_icon->set_state( isHIDDEN, ( text_editor->buf_len - delta_x ) < xl );
  102.   if( item_acted == this ) item_acted = owner;
  103. }
  104.  
  105. void Tinput_editor::convert_event( Tevent &ev )
  106. {
  107.   Tevent svd;
  108.  
  109.   svd = ev;
  110.   Teditor::convert_event( ev );
  111.   if( ( ev.code == evCOMMAND ) && ( ev.CMD_CODE >= cmeLINE_UP ) &&
  112.      ( ev.CMD_CODE <= cmeNEW_LINE ) ) ev = svd;
  113. }
  114.  
  115.  
  116. //Tinput publics:
  117.  
  118. Tinput::Tinput( char *_prompt, char *_line, int _max_length, int _xl ):
  119.   Tcombo_item( _prompt, _xl + 3 )
  120. {
  121.   init( _line, _max_length, _xl );
  122. #ifndef NOHIST
  123.   history_id = NULL;
  124. #endif
  125. }
  126.  
  127. #ifndef NOHIST
  128. Tinput::Tinput( char *_prompt, char *_line, int _max_length, int _xl, Tlb_list *_hist ):
  129.   Tcombo_item( _prompt, _xl + 3, _hist )
  130. {
  131.   init( _line, _max_length, _xl );
  132.   put_in( NEW( Thistory( _hist ) ), xl, 0 );
  133. }
  134. #endif
  135.  
  136. void Tinput::set_data( uint i )
  137. {
  138.   char s[256];
  139.  
  140.   gettxt( i, s );
  141.   set_txt( s );
  142. }
  143.  
  144. void Tinput::get_data( char *s )
  145. {
  146.   editor->text_editor->get_line_str( s, editor->text_editor->buf_len );
  147. }
  148.  
  149. void Tinput::set_txt( char *s )
  150. {
  151.   char tmp[256];
  152.  
  153.   strcpy( tmp, s );
  154.   if( strlen( tmp ) > editor->text_editor->buf_size ) tmp[editor->text_editor->buf_size] = 0;
  155.   editor->text_editor->set_select( 0, editor->text_editor->buf_len, 1 );
  156.   editor->text_editor->insert_string( tmp, 0 );
  157.   redraw();
  158.   item_acted = this;
  159. }
  160.  
  161. void Tinput::get_txt( char *s )
  162. {
  163.   editor->text_editor->get_line_str( s, editor->text_editor->buf_len );
  164. }
  165.  
  166. //Tinput protected:
  167.  
  168. void Tinput::draw( void )
  169. {
  170. #ifndef HGR
  171.   if( !graph_flag )
  172.   {
  173.     selected_attr = rolb( selected_attr, 4 );
  174.     text_attr = rolb( text_attr, 4 );
  175.     txtf( "|%c%s|r%c %s", state(isDISABLED)?'d':'t', i_left_line, xl - 2, i_right_line );
  176.     return;
  177.   }
  178. #endif
  179.   txtf( "%s|r%c %s", i_left_line, xl - 2, i_right_line );
  180. }
  181.  
  182. void Tinput::get_focused( void )
  183. {
  184.   editor->text_editor->set_select( 0, editor->text_editor->buf_len, 1 );
  185. }
  186.  
  187. boolean Tinput::release_focus( void )
  188. {
  189.   if( Tcombo_item::release_focus() )
  190.   {
  191.     editor->text_editor->hide_select();
  192.     return 1;
  193.   }
  194.   return 0;
  195. }
  196.  
  197. //Tinput private:
  198.  
  199. void Tinput::init( char *_line, int _max_length, int _xl )
  200. {
  201.   editor = NEW( Tinput_editor( _line, _max_length, _xl + 1 ) );
  202.   put_in( editor, 1, 0 );
  203.   put_in( NEW( Tline0( xl ) ), x, 1 );
  204.   put_in( NEW( Tline1( xl ) ), x, -1 );
  205. }
  206.  
  207.  
  208. //Tlinput publics:
  209.  
  210. Tlinput::Tlinput ( char *_prompt, long &_data, long _min, long _max ):
  211.   Tinput( _prompt, lin, len, init_len( _min, _max ) )
  212. {
  213.   init( _data, _min, _max );
  214. }
  215.  
  216. #ifndef NOHIST
  217. Tlinput::Tlinput( char *_prompt, long &_data, long _min, long _max, Tlb_list *_hist ):
  218.   Tinput( _prompt, lin, len, init_len( _min, _max ), _hist )
  219. {
  220.   init( _data, _min, _max );
  221. }
  222. #endif
  223.  
  224. boolean Tlinput::valid( uint stop_st )
  225. {
  226.   long v;
  227.   char line[256], *end_ptr;
  228.   Tcombo_item::valid( stop_st );
  229.   if( stop_st == cmCANCEL ) return 1;
  230.   get_txt( line );
  231.   v = strtol( line, &end_ptr, hex?16:10 );
  232.   if( (!v && *end_ptr) || v<min || v>max )
  233.   {
  234. #ifdef CYR
  235.     sprintf( line, "æ▓«⌐¡«▒▓▓á ¡Ñ Ñ ó὿ñ¡á.\n\n┐ ó║óÑñÑ▓Ñ ñ░│ú« ╢┐½« ╖¿▒½« ¼Ñªñ│ %%l%c ¿ %%l%c ", hex?'x':'d', hex?'x':'d' );
  236. #else
  237.     sprintf( line, "Value not within the valid range.\n\nPlease enter new integer value between %%l%c and %%l%c ", hex?'x':'d', hex?'x':'d' );
  238. #endif
  239.     focus(); _terror();
  240.     ok( line, min, max );
  241.     return 0;
  242.   }
  243.   *data = v;
  244.   return 1;
  245. }
  246.  
  247. void Tlinput::set_num( long n )
  248. {
  249.   char s[256];
  250.  
  251.   n = maxl( n, min );
  252.   n = minl( n, max );
  253.   ltoa( n, s, hex?16:10 );
  254.   set_txt( s );
  255. }
  256.  
  257. long Tlinput::get_num( void )
  258. {
  259.   char s[256];
  260.  
  261.   get_txt( s );
  262.   return atol( s );
  263. }
  264.  
  265. //Tlinput private:
  266.  
  267. char Tlinput::init_len( long _min, long _max )
  268. {
  269.   hex = __hexnum();
  270.   ltoa( _min, lin, hex?16:10 ); len = (char) strlen( lin );
  271.   ltoa( _max, lin, hex?16:10 ); if( strlen( lin ) > len ) len = (char) strlen( lin );
  272.   return len;
  273. }
  274.  
  275. void Tlinput::init( long &_data, long _min, long _max )
  276. {
  277.   ltoa( _data, lin, hex?16:10 );
  278.   set_txt( lin );
  279.   data = &_data; min = _min; max = _max;
  280.   ~editor->text_editor->valid_chars;
  281.   editor->text_editor->valid_chars << '-';
  282.   for( int i = '0'; i <= '9'; i++ )
  283.     editor->text_editor->valid_chars << i;
  284.   if( hex )
  285.   {
  286.     for( i = 'A'; i <= 'F'; i++ )
  287.       editor->text_editor->valid_chars << i;
  288.     for( i = 'a'; i <= 'f'; i++ )
  289.       editor->text_editor->valid_chars << i;
  290.   }
  291. }
  292.  
  293.  
  294. //Tiinput publics:
  295.  
  296. Tiinput::Tiinput( char *_prompt, int &_data, int _min, int _max ):
  297.   Tlinput( _prompt, tmp, _min, _max )
  298. {
  299.   set_num( _data );
  300.   tmp = _data;
  301.   dta = &_data;
  302. }
  303.  
  304. #ifndef NOHIST
  305. Tiinput::Tiinput( char *_prompt, int &_data, int _min, int _max, Tlb_list *_hist ):
  306.   Tlinput( _prompt, tmp, _min, _max, _hist )
  307. {
  308.   set_num( _data );
  309.   tmp = _data;
  310.   dta = &_data;
  311. }
  312. #endif
  313.  
  314. boolean Tiinput::valid( uint stop_st )
  315. {
  316.   boolean result;
  317.  
  318.   result = Tlinput::valid( stop_st );
  319.   *dta = tmp;
  320.   return result;
  321. }
  322.  
  323.  
  324. //Tsinput publics:
  325.  
  326. Tsinput::Tsinput( char *_prompt, short &_data, short _min, short _max ):
  327.   Tlinput( _prompt, tmp, _min, _max )
  328. {
  329.   set_num( _data );
  330.   tmp = _data;
  331.   dta = &_data;
  332. }
  333.  
  334. #ifndef NOHIST
  335. Tsinput::Tsinput( char *_prompt, short &_data, short _min, short _max, Tlb_list *_hist ):
  336.   Tlinput( _prompt, tmp, _min, _max, _hist )
  337. {
  338.   set_num( _data );
  339.   tmp = _data;
  340.   dta = &_data;
  341. }
  342. #endif
  343.  
  344. boolean Tsinput::valid( uint stop_st )
  345. {
  346.   boolean result;
  347.  
  348.   result = Tlinput::valid( stop_st );
  349.   *dta = (short) tmp;
  350.   return r